package day2.homework;

import java.io.*;

public
class Demo2 {
    public static
    void main(String[] args) {
        try(FileInputStream fis =new FileInputStream("D:\\IO\\movie\\1.mp4");
            FileOutputStream fos =new FileOutputStream("D:\\IO\\movie\\11.mp4");
            BufferedInputStream bis=new BufferedInputStream(fis);
            BufferedOutputStream bos=new BufferedOutputStream(fos)
        )
        {
            File f=new File("D:\\IO\\movie\\1.mp4");
            int len;
            long size=f.length();
            System.out.println("文件总大小："+size+"字节");
            long i=0;
            int x=1;
            byte[] bs=new byte[1024];
            //获取开始时间
            long start=System.currentTimeMillis();
            while((len=bis.read(bs))!=-1){
                i+=len;
                bos.write(bs,0,len);
                if(i>=size/10*x){
                    System.out.print("当前进度："+(x*10)+"% ");
                    long end=System.currentTimeMillis();
                    System.out.println("耗时："+(end-start)+"ms");
                    x++;
                }
            }
            //获取结束时间
            long end=System.currentTimeMillis();
            System.out.println("复制完毕，耗时："+(end-start)+"ms");
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
